package com.zxy.ziems.server.device.controller;

import com.zxy.btp.common.response.JsonResponse;
import com.zxy.btp.common.response.PageResult;
import com.zxy.ziems.server.device.pojo.dto.DeviceCustomDataDTO;
import com.zxy.ziems.server.device.pojo.param.DeviceCustomDataParam;
import com.zxy.ziems.server.device.pojo.vo.DeviceCustomDataVO;
import com.zxy.ziems.server.device.service.DeviceCustomDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 手工录入（自定义数据）
 */
@RestController
@RequestMapping("/api/custom/data")
public class DeviceCustomDataController {

    @Autowired
    private DeviceCustomDataService deviceCustomDataService;

    /**
     * 列表
     * @param param
     * @return
     */
    @RequestMapping("/page")
    public PageResult<DeviceCustomDataVO> page(@Validated DeviceCustomDataParam param) {
        return deviceCustomDataService.page(param);
    }

    /**
     * 新增自定义项
     * @param dtos
     * @return
     */
    @PostMapping("/add")
    public JsonResponse<Void> add(@Validated(DeviceCustomDataDTO.Add.class) @RequestBody List<DeviceCustomDataDTO> dtos) {
        deviceCustomDataService.adds(dtos);
        return JsonResponse.SUCCESS();
    }

    /**
     * 添加或修改自定义项的值
     * @param dto
     * @return
     */
    @PostMapping("/addVal")
    public JsonResponse<Void> addVal(@Validated(DeviceCustomDataDTO.AddVal.class) @RequestBody DeviceCustomDataDTO dto) {
        deviceCustomDataService.addVal(dto);
        return JsonResponse.SUCCESS();
    }

    /**
     * 删除录入数据
     * @param dto
     * @return
     */
    @PostMapping("/removeVal")
    public JsonResponse<Void> removeVal(@Validated(DeviceCustomDataDTO.Delete.class) @RequestBody DeviceCustomDataDTO dto) {
        deviceCustomDataService.removeVal(dto);
        return JsonResponse.SUCCESS();
    }
}
